package com.nineclock.attendance.controller;

import com.nineclock.attendance.dto.AttendHolidayDTO;
import com.nineclock.attendance.dto.AttendSettingDTO;
import com.nineclock.attendance.dto.AttendOvertimeRuleDTO;
import com.nineclock.attendance.pojo.AttendHoliday;
import com.nineclock.attendance.service.AttendHolidayService;
import com.nineclock.attendance.service.AttendSettingService;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/rule")
@Api(value = "考勤组管理接口", tags = "考勤服务")
public class AttendHolidayController {

    @Autowired(required = false)
    private AttendHolidayService holidayService;

    @Autowired(required = false)
    private AttendSettingService settingService;

    /**
     * 接口名称：考勤: 假期管理
     * 接口路径：GET/atte/rule/holiday
     */
    @GetMapping("/holiday")
    @ApiOperation("假期管理")
    public Result<PageResult<AttendHolidayDTO>> queryHoliday(@RequestParam(defaultValue = "1") Integer page,
                                                             @RequestParam(defaultValue = "10") Integer pageSize){

        PageResult<AttendHolidayDTO> dtoPageResult = holidayService.queryHoliday(page, pageSize);
        return Result.success(dtoPageResult);
    }

    /**
     * 接口名称：考勤: 更新假期
     * 接口路径：GET/atte/rule/holiday/{id}
     */
    @ApiOperation("考勤: 更新假期")
    @PutMapping("/holiday/{id}")
    public Result updateHoliday(@PathVariable("id") Long id, @RequestBody AttendHolidayDTO holidayDTO) {
        holidayService.updateHoliday(id, holidayDTO);
        return Result.success();
    }

    /**
     * 接口名称：考勤: 删除假期
     * 接口路径：Delete/atte/rule/holiday/{id}
     */
    @DeleteMapping("/holiday/{id}")
    @ApiOperation("考勤: 删除假期")
    public Result removeHoliday(@PathVariable("id") Long id) {
        holidayService.removeHoliday(id);
        return Result.success();
    }

    /**
     * 接口名称：考勤: 添加假期
     * 接口路径：Post/atte/rule/holiday
     */
    @PostMapping("/holiday")
    @ApiOperation("考勤: 添加假期")
    public Result addHoliday(@RequestBody HashMap<String, Object> map){
        holidayService.addHoliday(map);
        return Result.success();
    }


    /**
     * 接口名称：考勤: 补卡规则
     * 接口路径：Post/atte/rule/makeup
     */
    @GetMapping("/makeup")
    @ApiOperation("考勤: 补卡规则")
    public Result<PageResult<AttendSettingDTO>> querySetting(@RequestParam(defaultValue = "1") Integer page,
                                                             @RequestParam(defaultValue = "10") Integer pageSize){

        PageResult<AttendSettingDTO> settingDTOPageResult = settingService.querySetting(page, pageSize);
        return Result.success(settingDTOPageResult);
    }

    /**
     * 接口名称：考勤: 补卡规则
     * 接口路径：Put/atte/rule/makeup/{id}
     */
    @PutMapping("/makeup/{id}")
    @ApiOperation("考勤: 修改补卡")
    public Result updateSetting(@RequestBody Map<String, Object> map) {
        settingService.updateSetting(map);
        return Result.success();
    }

    /**
     * 接口名称：考勤: 加班规则
     * 接口路径：GET/atte/rule/overtime
     */
    @GetMapping("/overtime")
    @ApiOperation("加班规则")
    public Result<PageResult<AttendOvertimeRuleDTO>> queryOverTime(@RequestParam(defaultValue = "1") Integer page,
                                                                   @RequestParam(defaultValue = "10") Integer pageSize){

        PageResult<AttendOvertimeRuleDTO> dtoPageResult = holidayService.queryOverTime(page, pageSize);
        return Result.success(dtoPageResult);
    }
    /**
     * 接口名称：考勤: 加班规则
     * 接口路径：GET/atte/rule/overtime
     */
    @GetMapping("/overtime/{id}")
    @ApiOperation("加班规则编辑回显")
    public Result<AttendOvertimeRuleDTO> queryOverTimeById(@PathVariable Long id){

        AttendOvertimeRuleDTO attendOvertimeRuleDTO = holidayService.queryOverTimeById(id);
        return Result.success(attendOvertimeRuleDTO);
    }
    /**
     * 接口名称：考勤: 加班规则
     * 接口路径：Delete/atte/rule/overtime
     */
    @DeleteMapping("/overtime/{id}")
    @ApiOperation("删除加班规则")
    public Result<AttendOvertimeRuleDTO> deleteOverTimeById(@PathVariable Long id){

         holidayService.deleteOverTimeById(id);
        return Result.success();
    }
    /**
     * 接口名称：考勤: 加班规则
     * 接口路径：Post/atte/rule/overtime
     */
    @DeleteMapping("/overtime")
    @ApiOperation("新增加班规则")
    public Result insertOverTime(AttendOvertimeRuleDTO overtimeRuleDTO){
        holidayService.insert(overtimeRuleDTO);
        return Result.success();
    }
}
